package com.tarena.lbs.attach.service.impl;

import com.tarena.lbs.attach.pojo.vo.FileVO;
import com.tarena.lbs.attach.service.AttachService;
import com.tarena.lbs.attach.utils.FileUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.UUID;
@Slf4j
@Service
public class AttachServiceImpl implements AttachService {
    @Value("${image_path}")
    private String imageUrl;
    @Value("${url}")
    private String url;
    public FileVO uploadAttachInfo(MultipartFile file) throws Exception {
        log.info("开始文件上传");
        String path = imageUrl + "/picture/";
        String fileUuid = UUID.randomUUID().toString();
        String fileName = FileUtil.makeTempFile(file, path, fileUuid);
        FileVO fileVO = new FileVO();
        fileVO.setUrl(url + "/picture/" + fileName);
        fileVO.setFileUuid(fileUuid);
        // TODO 保存文件信息到数据库  练习就传死值了
        fileVO.setId(2);
        log.info("文件上传完成");
        return fileVO;
    }
}
